package com.stox.ui.swing.widget;


import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.OrderComparator;
import org.springframework.stereotype.Component;

import com.stox.ui.swing.widget.wrapper.JMenu;
import com.stox.ui.swing.widget.wrapper.JMenuBar;

@Component
public class MenuBar extends JMenuBar implements InitializingBean{
	private static final long serialVersionUID = -5405095626361510480L;
	
	@Autowired
	private ApplicationContext applicationContext;
	
	@Override
	public void afterPropertiesSet() throws Exception {
		List<JMenu> jmenus = new ArrayList<JMenu>(applicationContext.getBeansOfType(JMenu.class).values());
		OrderComparator.sort(jmenus);
		for(JMenu jmenu : jmenus){
			add(jmenu);
		}
	}
	
}
